package com.smedi.ismedi.cronjob.core.application.service.impl;

import com.smedi.ismedi.cronjob.core.application.command.JobInfoCommand;
import com.smedi.ismedi.cronjob.core.application.command.JobRunCommand;
import com.smedi.ismedi.cronjob.core.application.service.JobApplicationService;
import com.smedi.ismedi.cronjob.core.domain.aggregatemodel.JobInfo;
import com.smedi.ismedi.cronjob.core.domain.aggregatemodel.JobRun;
import com.smedi.ismedi.cronjob.core.domain.service.JobInfoDomainService;
import com.smedi.ismedi.cronjob.core.domain.service.JobRunDomainService;
import com.smedi.ismedi.web.starter.util.DozerUtil;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@AllArgsConstructor
public class CronjobApplicationServiceImpl implements JobApplicationService {
    private final DozerUtil dozerUtil;

    private final JobInfoDomainService jobInfoDomainService;

    private final JobRunDomainService jobRunDomainService;

    @Override
    public Boolean runJob(JobInfoCommand jobInfoCommand) {
        JobInfo cronjob = dozerUtil.convertor(jobInfoCommand, JobInfo.class);
        return jobInfoDomainService.runJob(cronjob);
    }

    @Override
    public Boolean pauseJob(JobInfoCommand jobInfoCommand) {
        JobInfo cronjob = dozerUtil.convertor(jobInfoCommand, JobInfo.class);
        return jobInfoDomainService.pauseJob(cronjob);
    }

    @Override
    public Boolean resumeJob(JobInfoCommand jobInfoCommand) {
        JobInfo cronjob = dozerUtil.convertor(jobInfoCommand, JobInfo.class);
        return jobInfoDomainService.resumeJob(cronjob);
    }

    @Override
    public Boolean refreshJob(JobInfoCommand jobInfoCommand) {
        JobInfo cronjob = dozerUtil.convertor(jobInfoCommand, JobInfo.class);
        return jobInfoDomainService.refreshJob(cronjob);
    }

    @Override
    public List<JobInfo> restartAllJob() {
        return jobInfoDomainService.restartAllJob();
    }

    @Override
    public JobInfo insertJob(JobInfoCommand jobInfoCommand) {
        JobInfo cronjob = dozerUtil.convertor(jobInfoCommand, JobInfo.class);
        return jobInfoDomainService.insertJob(cronjob);
    }

    @Override
    public boolean deleteJob(JobInfoCommand jobInfoCommand) {
        JobInfo cronjob = dozerUtil.convertor(jobInfoCommand, JobInfo.class);
        return jobInfoDomainService.deleteJob(cronjob);
    }

    @Override
    public JobInfo updateJob(JobInfoCommand jobInfoCommand) {
        JobInfo cronjob = dozerUtil.convertor(jobInfoCommand, JobInfo.class);
        return jobInfoDomainService.updateJob(cronjob);
    }

    @Override
    public JobInfo getJob(Long id) {
        return jobInfoDomainService.getJob(id);
    }

    @Override
    public List<JobInfo> listJob(JobInfoCommand jobInfoCommand) {
        JobInfo jobInfo = dozerUtil.convertor(jobInfoCommand, JobInfo.class);
        return jobInfoDomainService.listJob(jobInfo);
    }

    @Override
    public JobRun updateJobRun(JobRunCommand jobRunCommand) {
        JobRun cronjobRun = dozerUtil.convertor(jobRunCommand, JobRun.class);
        return jobRunDomainService.updateJobRun(cronjobRun);
    }

    @Override
    public JobRun getJobRun(Long id) {
        return jobRunDomainService.getJobRun(id);
    }

    @Override
    public List<JobRun> listJobRun(JobRunCommand jobRunCommand) {
        return null;
    }
}
